package com.lh.dao;

import com.lh.entity.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: LuoHang
 * @Date: 2021/1/26 15:42
 * @Description
 */
@Repository
public class UserDao {
    @Autowired
    private SqlSessionTemplate sessionTemplate;

    public User login(Map<String,Object> map){
        return sessionTemplate.selectOne("UserMapper.login",map);
    }

    public int register(Map<String,Object> map){
        return sessionTemplate.insert("UserMapper.register",map);
    }

    public int update(Map<String,Object> map){
        return sessionTemplate.update("UserMapper.update",map);
    }

    public List<User> getUsers(Map<String,Object> map){
        return sessionTemplate.selectList("UserMapper.getUsers",map);
    }

    public int getCount(Map<String,Object> map) {
        return sessionTemplate.selectOne("UserMapper.getCount",map);
    }

    public User getUserById(Integer id){
        return  sessionTemplate.selectOne("UserMapper.getUserById",id);
    }

    public int deleteUserById(Integer id){
        return sessionTemplate.delete("UserMapper.deleteUserById",id);
    }

    public int addUser(Map<String,Object> map){
        return sessionTemplate.insert("UserMapper.addUser",map);
    }

    public int getRoleUserCount(Integer roleId){
        return sessionTemplate.selectOne("UserMapper.getRoleUserCount",roleId);
    }

    public int getRegisterCountByDay(Date gmtCreate){
        return sessionTemplate.selectOne("UserMapper.getRegisterCountByDay",gmtCreate);
    }
}
